package com.hsy.linemoney.modules.my.mydeals;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.deparse.dpframe.tools.utils.DPUnitUtil;
import com.deparse.dpframe.ui.android.widget.DPViewPager;
import com.deparse.dpframe.ui.android.widget.DPagerSlidingTabStrip;
import com.hsy.linemoney.R;
import com.hsy.linemoney.modules.common.CommonBaseActivityWithSimpleActionBar;


import java.util.ArrayList;
import java.util.List;

/**
 * 我的交易
 * Created by Administrator on 2016/7/11.
 */
public class MyDealsActivity extends CommonBaseActivityWithSimpleActionBar {
    private DPViewPager activity_repair_viewpager;
    private List<Fragment> fragments;
    private DPagerSlidingTabStrip tabs;
    private MyPagerAdapter adapter;
//    private DPViewPager.OnPageChangeListener onPageChangeListener = new DPViewPager.OnPageChangeListener() {
//        @Override
//        public void onPageScrolled(int i, float v, int i1) {
//
//        }
//
//        @Override
//        public void onPageSelected(int i) {
//            if (i == 0) {
//                ((TextView) ((ViewGroup) tabs.getChildAt(0)).getChildAt(0)).setTextColor(getResources().getColor(R.color.common_green));
//                ((TextView) ((ViewGroup) tabs.getChildAt(0)).getChildAt(1)).setTextColor(getResources().getColor(R.color.tab_title_color_normal));
//            } else {
//                ((TextView) ((ViewGroup) tabs.getChildAt(0)).getChildAt(0)).setTextColor(getResources().getColor(R.color.tab_title_color_normal));
//                ((TextView) ((ViewGroup) tabs.getChildAt(0)).getChildAt(1)).setTextColor(getResources().getColor(R.color.common_green));
//            }
//        }
//
//        @Override
//        public void onPageScrollStateChanged(int i) {
//
//        }
//    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.title_my_new_deals);
        setContentView(R.layout.activity_my_tender);
        activity_repair_viewpager = F(R.id.activity_repair_viewpager);

        tabs = F(R.id.tabs);

//        tabs.setOnPageChangeListener(onPageChangeListener);

        tabs.setVisibility(View.GONE);
        showTab();
    }

    private void showTab() {
        fragments = new ArrayList<Fragment>();
//        PartDealedFragment partDealedFragment = new PartDealedFragment();
        WaitDealFragment waitDealFragment = new WaitDealFragment();
//        partDealedFragment.setAttchedActivity(this);
        waitDealFragment.setAttchedActivity(this);
//        fragments.add(partDealedFragment);
        fragments.add(waitDealFragment);

        adapter = new MyPagerAdapter(getSupportFragmentManager(), fragments);

//        tabs.setTextSize(DPUnitUtil.dip2px(this, 16));
//        tabs.setIndicatorWidth(DPUnitUtil.dip2px(this, 60));
//        tabs.setIndicatorHeight(1);
//        tabs.setUnderlineHeight(0);

        int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
        activity_repair_viewpager.setAdapter(adapter);
        activity_repair_viewpager.setPageMargin(pageMargin);
        tabs.setViewPager(activity_repair_viewpager);

//        onPageChangeListener.onPageSelected(0);
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {

        private final String[] TITLES = {getResources().getString(R.string.tab_title_wait_deal)};
        private List<Fragment> myFragmentsList;

        public MyPagerAdapter(FragmentManager fragmentmanager, List<Fragment> list) {
            super(fragmentmanager);
            myFragmentsList = list;
        }

        public int getItemPosition(Object obj) {
            return super.getItemPosition(obj);
        }

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        public int getCount() {
            return myFragmentsList.size();
        }

        public Fragment getItem(int i) {
            return (Fragment) myFragmentsList.get(i);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }

    }
}
